check_function_exists(getopt HAVE_GETOPT)
foreach(PROGRAM zipcmp zipmerge ziptool)
  add_executable(${PROGRAM} ${PROGRAM}.c)
  target_link_libraries(${PROGRAM} zip)
  target_include_directories(${PROGRAM} PRIVATE BEFORE ${PROJECT_SOURCE_DIR}/lib ${PROJECT_BINARY_DIR})
  if(LIBZIP_DO_INSTALL)
    install(TARGETS ${PROGRAM} EXPORT ${PROJECT_NAME}-targets RUNTIME DESTINATION bin)
  endif()
  if(NOT HAVE_GETOPT)
    target_sources(${PROGRAM} PRIVATE getopt.c)
  endif(NOT HAVE_GETOPT)
endforeach()
target_link_libraries(zipcmp ${FTS_LIB} ZLIB::ZLIB)
